#!usr/bin/perl -w
use strict;

my $file;
my $seqID;
my $start;
my $end;
my $strand;
my $chx;
my $last_col;


open(DATA,"cglo_TE.fasta")  || die "cannot open file $file: $!\n";

print"##gff-version 3\n";
while(<DATA>)
{
	
	if(/^>/)
	{
		my @row = split(/\s+/,$_);
		$seqID = $row[0];
		$seqID =~ s/>(\S+)/$1/;
		#print"$seqID\n";
		
		$start = $row[4];
		$start =~ s/Location:\((\d+)/$1/;
		#print"$start\n";
		
		$end = $row[6];
		$end =~ s/(\d+)\)/$1/;
		#print"$end\n";
		
		
		$strand = $row[7];
		$strand =~ s/Direction:(\S+)/$1/;
		$strand =~ s/plus/+/;
		$strand =~ s/minus/-/;
		#print"$strand\n";
		
		$chx = $row[2];
		$chx =~ s/Sbjct:(\S+)/$1/;
		#print "$chx\n";
		
		
		my $first_half = "ID=".$chx;
		my @part = ($first_half, $seqID, $start, $end);
		my $ID_part = join ".", @part;
		my $Name_part = "Name=".$seqID;
		my @whole = ($ID_part, $Name_part);
		$last_col = join ";", @whole;
		#print "$last_col\n";
		#$printf"%-10s	%s	%s	%10d	%10d	%s	%s	%s	%s\n", 
		#$chx, 'TARGeT','TE_insertion', $start,$end,'.',$strand,'.',$last_col;
		print "$chx\tTARGeT\tTE_insertion\t$start\t$end\t.\t$strand\t.\t$last_col\n";
	}
}